<template>
  <div>
      <el-table
      :data="tableData"
      style="width: 100%">
      <el-table-column
        prop="gid"
        label="商品id"
        width="180">
      </el-table-column>
      <el-table-column
        prop="goodsname"
        label="商品名"
        width="180">
      </el-table-column>
      <el-table-column
        prop="status"
        label="商品状态"
        width="180">
      </el-table-column>
      <el-table-column
        prop="district"
        label="商品分区"
        width="180">
      </el-table-column>
      <el-table-column
        prop="counts"
        label="商品数量"
        width="180">
      </el-table-column>
      <el-table-column
        prop="price"
        label="商品价格"
        width="180">
      </el-table-column>
      <el-table-column
        prop="sellersId"
        label="商家id"
        width="180">
      </el-table-column>
     <el-table-column
        label="操作"
        width="100">
      <template slot-scope="scope">
        <el-button @click="goodsDelete(scope.row)" type="text" size="small">删除</el-button>
        <el-button @click="goodsFind(scope.row)" type="text" size="small">编辑</el-button>
      </template>
     </el-table-column>
    </el-table>
    <el-pagination
      background
      current-page
      page-size=3
      prev-page="上一页"
      next-page="下一页"
      @current-change="currentPage"
      layout="prev, pager, next , jumper, total"
      :total="total">
    </el-pagination>
  </div>
</template>

<script>
    export default {
    methods: {
        currentPage(page){
          let _this = this
          axios.get('http://localhost:8888/chuyangc/goods/pagelist/' + page).then(function (response){
          _this.tableData = response.data.list
          _this.total = response.data.total
          console.log(response)
        })
        },
        goodsDelete(row) {
          let _this = this
          this.$confirm('是否确认要删除'+row.goodsname+'?', '删除数据', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
          }).then(() => {
                  let url = "http://localhost:8888/chuyangc/goods/delete/" + row.gid
                  axios.delete(url).then(function (response) {
                  if (response.data) {
                      _this.$alert(row.goodsname + "删除成功",'删除数据',{
                      confirmButtonText: '确定',
                      callback: action => {
                          location.reload()
                      }
                      });
                  }
                  })
              }
              ).catch(() => {
          });
        },
        goodsFind(row){
            this.$router.push('/goodsedit?gid=' + row.gid)
        }
    },
    created() {
        let _this = this
        axios.get('http://localhost:8888/chuyangc/goods/pagelist/1').then(function (response){
            _this.tableData = response.data.list
            _this.total = response.data.total
            console.log(response)
        })
    },
    data() {
        return {
          tableData: null,
          total:0
        }
    }
    }
</script>